package com.example.senior_homework.repository.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.example.senior_homework.entity.Senior
import java.util.Date

@Dao
interface SeniorDao {

    // 查询所有记录
    @Query("SELECT * FROM seniors")
    suspend fun getAll(): List<Senior>

    // 根据ID查询单个记录
    @Query("SELECT * FROM seniors WHERE id = :id")
    suspend fun findById(id: Int): Senior?

    // 插入一条新的记录
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertSenior(senior: Senior)

    // 更新一条记录
    @Update
    suspend fun updateSenior(senior: Senior)

    // 删除一条记录
    @Delete
    suspend fun deleteSenior(senior: Senior)

    // 根据ID删除一条记录
    @Query("DELETE FROM seniors WHERE id = :id")
    suspend fun deleteById(id: Int)

    // 删除所有记录
    @Query("DELETE FROM seniors")
    suspend fun deleteAll()

    // 查询在某天的所有记录
    @Query("SELECT * FROM seniors WHERE data_time = :date")
    suspend fun findByDate(date: Date): List<Senior>

    @Query("select * from seniors where if_upload= false")
    suspend fun findNoUploaded():List<Senior>
}